package com.inspur.security.cbb3.kms.keks.controller;

import com.inspur.security.cbb3.kms.annotation.SysLog;
import com.inspur.security.cbb3.kms.enums.BusinessType;
import com.inspur.security.cbb3.kms.enums.SystemCode;
import com.inspur.security.cbb3.kms.exception.UserInfoInVaildException;
import com.inspur.security.cbb3.kms.keks.po.KeksBean;
import com.inspur.security.cbb3.kms.keks.service.KeksService;
import com.inspur.security.cbb3.kms.sysuser.po.SysUserBean;
import com.inspur.security.cbb3.kms.sysuser.service.SysUserService;
import com.inspur.security.cbb3.kms.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * KeksController
 *
 * @author liukai
 * @date 2020/10/26
 **/

@RestController
@RequestMapping("/v1/keks")
public class KeksController {

    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private KeksService keksService;

    @PostMapping
    @SysLog(title = "新增二级主密钥", businessType = BusinessType.EXPORT)
    public ResponseEntity addKeks(KeksBean keksBean){
//参数校验
        SysUserBean loginUser = sysUserService.findLoginSysUser();
        if(loginUser==null){
            throw new UserInfoInVaildException();
        }
        keksBean.setCreatorId(loginUser.getUuid());
        KeksBean keksBean1 = keksService.addKek(keksBean);
        return ResultUtil.dataReturn(SystemCode.SUCCESS, keksBean1, HttpStatus.OK);
    }
}
